<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="conditionQuery.name" placeholder="员工姓名"/>
      </el-form-item>

      <el-form-item>
        <el-select v-model="conditionQuery.area" clearable placeholder="所属部门">
          <el-option :value="1" label="设备A"/>
          <el-option :value="2" label="设备B"/>
        </el-select>
      </el-form-item>

      <el-form-item label="时间段">
        <el-date-picker
          v-model="conditionQuery.begin"
          type="datetime"
          placeholder="选择入职时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="conditionQuery.end"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>


    <!-- 表格 -->
    <el-table
      :data="list"
      :row-class-name="tableRowClassName">

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <!-- 这里的scope可以代表整个表格 -->
        <template slot-scope="scope">
          {{ (page - 1) * size + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="员工姓名" />

      <el-table-column label="所属部门" width="80">
        <template slot-scope="scope">
          {{ scope.row.area===1?'销售部':'运营部' }}
        </template>
      </el-table-column>


      <el-table-column prop="phone" label="联系方式" width="150"/>

      <el-table-column prop="gmtCreate" label="入职时间" width="160"/>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="'/teacher/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <!-- scope.row可以获取表格中每一行的数据-->
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页条 -->
    <el-pagination
      :current-page="page"
      :page-size="size"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>
</template>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
<script>
export default {
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1 || rowIndex === 5 || rowIndex === 9) {
        return 'warning-row';
      } else if (rowIndex === 3 || rowIndex === 7) {
        return 'success-row';
      }
      return '';
    }
  },
  //写核心代码的位置
  data() { //定义变量和初始值
    return {
      list: [
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },{
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        },
        {
          name: '张三',
          area: 1,
          principal: '张三',
          phone: '13111111111',
          status: '否',
          gmtCreate: '2021-5-25'
        }
      ], //查询之后接口返回的集合
      page: 1,//当前页
      size: 10,//每页显示的记录数
      total: 12345,//总记录数
      conditionQuery: {},//条件查询对象,
    }
  }
}
</script>

